package com.chenju.invokechainservice.test;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class FindSettingsGradleFiles {
    public static void main(String[] args) {
        String projectDirectory = "D:\\Project\\testgit\\project"; // 请将路径替换为你的项目根目录路径
        List<String> settingsGradlePaths = findSettingsGradleFiles(projectDirectory);

        System.out.println("Found " + settingsGradlePaths.size() + " settings.gradle files:");
        for (String path : settingsGradlePaths) {
            System.out.println(path);
        }
    }

    public static List<String> findSettingsGradleFiles(String directoryPath) {
        List<String> settingsGradlePaths = new ArrayList<>();
        File directory = new File(directoryPath);

        if (directory.exists() && directory.isDirectory()) {
            findSettingsGradleFilesRecursively(directory, settingsGradlePaths);
        }

        return settingsGradlePaths;
    }

    private static void findSettingsGradleFilesRecursively(File directory, List<String> settingsGradlePaths) {
        File[] files = directory.listFiles();
        if (files != null) {
            for (File file : files) {
                if (file.isDirectory()) {
                    findSettingsGradleFilesRecursively(file, settingsGradlePaths);
                } else if (file.getName().equals("settings.gradle")) {
                    settingsGradlePaths.add(file.getAbsolutePath());
                }
            }
        }
    }
}

